const Controller = require('egg').Controller;

class HomeController extends Controller {
    async index() {
        //   this.ctx.body = 'Hello world';
        this.ctx.body = await this.app.mysql.query(`select 1+1;`); // 单实例可以直接通过 app.mysql 访问
    }

    async wxlogin() {
        var redirect_uri = encodeURIComponent('http://zzsc.test.utools.club/wxloginCallback')
        var appid = "wx328d50c4423ad581"
        // snsapi_login
        var url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
        // return this.redirect("https://baidu.com")
        return this.ctx.redirect(url)
    }

    async wxloginCallback() {
        var query = this.ctx.query
        return this.ctx.body = {
            query
        }
    }

}

module.exports = HomeController;